package com.xlh.service.problem.impl;

import com.xlh.dao.problem.ReplyMapper;
import com.xlh.dao.problem.ReplyMapperExt;
import com.xlh.dto.problem.ReplyDTO;
import com.xlh.param.problem.ReplyPostParam;
import com.xlh.pojo.problem.Reply;
import com.xlh.service.problem.ReplyService;
import com.xlh.util.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReplyServiceImpl implements ReplyService {
    @Autowired
    private ReplyMapper mapper;
    @Autowired
    private ReplyMapperExt mapperExt;

    @Override
    public List<ReplyDTO> replyList(Long id) {
        return mapperExt.replyList(id);
    }

    @Override
    public List<ReplyDTO> myReplyList(ReplyPostParam replyPostParam) {
        return mapperExt.myReplyList(replyPostParam);
    }

    @Override
    public void toAnswer(ReplyPostParam replyPostParam) {
        insertSelective(replyPostParam);
    }

    private void insertSelective(ReplyPostParam replyPostParam) {
        Reply reply = BeanUtil.transform(Reply.class, replyPostParam);
        if (reply != null) {
            mapper.insertSelective(reply);
        }
    }

    @Override
    public void batchDeletionAnswer(List<Integer> ids) {
        mapperExt.batchDeletionAnswer(ids);
    }

    @Override
    public void batchDeletionAnswerByProblemId(List<Integer> ids) {
        mapperExt.batchDeletionAnswerByProblemId(ids);
    }
}
